/*
* PROJECT: Happy New Year
* VERSION: 1.0
* AUTHOR: Mattias Thell
* URL: http://www.mattiasthell.com
*
* */

#include "HnyMenuItem.hpp"

HnyMenuItem::HnyMenuItem(int id_, hgeFont *font, float x, float y, std::string title)
	:mFont(font), mTitle(title)
{

	mOffset = 3.0f;
	mLight = hgeColor(0.5f, 0.5f, 1.0f, 1.0f);
	mShadow = hgeColor(0.1f, 0.1f, 0.1f, 1.0f);
	
	// Base class initialization
	id = id_;
	bStatic = false;
	bVisible = true;
	bEnabled = true;

	float w = mFont->GetStringWidth(title.c_str());
	rect.Set(x - w/2, y, x + w/2, y + mFont->GetHeight());
}

HnyMenuItem::~HnyMenuItem()
{
}

void HnyMenuItem::Render()
{
	mFont->SetColor(mShadow.GetHWColor());
	mFont->Render(rect.x1+mOffset, rect.y1+mOffset, HGETEXT_LEFT, mTitle.c_str());
	mFont->SetColor(mLight.GetHWColor());
	mFont->Render(rect.x1, rect.y1, HGETEXT_LEFT, mTitle.c_str());
}

void HnyMenuItem::Update(float dt)
{
	// TODO
}

/* Enter is called when the GUI is about to appear on the screen. 
   A control should start it's Enter animation here: */
void HnyMenuItem::Enter()
{
}

/* Leave is called when the GUI is about to disappear from the screen. 
   A control should start it's Leave animation here: */
void HnyMenuItem::Leave()
{
}

/* IsDone is used to test if the control has finished it's Enter/Leave animation. 
   When the animation is finished it should return true: */
bool HnyMenuItem::IsDone()
{
	/*
	if(mTimer ==-1.0f) return true;
	else return false;
	*/

	return true;
}

/* Focus method is called when the control gains or loses keyboard input focus. */
void HnyMenuItem::Focus(bool focused) 
{
	if(focused)
		mLight = hgeColor(1.0f, 1.0f, 1.0f, 1.0f);
	else
		mLight = hgeColor(0.5f, 0.5f, 1.0f, 1.0f);
}

/* MouseOver method is called to notify the control that the mouse cursor 
   has entered or left it's area. Here we just set the input focus to our 
   control when the mouse comes over it: */
void HnyMenuItem::MouseOver(bool bOver)
{
	if(bOver) gui->SetFocus(id);
}

/* MouseLButton method is called to notify the control that the left mouse button state has changed. 
   If the control changes it's state and wants the caller to be notified, it should return true: */
bool HnyMenuItem::MouseLButton(bool bDown)
{
	if(!bDown)
	{
		return true;
	}
	else 
	{
		return false;
	}
}

/* KeyClick method is called to notify the control that a key has been clicked. 
   If the control changes it's state and wants the caller to be notified, it should return true: */
bool HnyMenuItem::KeyClick(int key, int chr)
{
	if(key==HGEK_ENTER || key==HGEK_SPACE)
	{
		MouseLButton(true);
		return MouseLButton(false);
	}

	return false;
}


